import { Injectable } from '@angular/core';
import {HttpService} from "@core/http/http.service";
import {ToolsService} from "@shared/service/tools/tools.service";
import {Router} from "@angular/router";
import {Observable} from "rxjs/Rx";
import {Response} from "@angular/http";
import * as API from "@api/index";
import {CommonPageVo, GoodsResp, SNSResult} from "@interface/index";
import {HaggleActivityRespVO, HaggleInitiatorRespVO} from "../../interface/haggle/haggle.model";

@Injectable()
export class HaggleService {

  constructor(
    private httpService: HttpService,
    private tools: ToolsService
  ) {
  }

  /**
   * @description 获取砍价活动信息
   * @author zhupw1360
   * @date 2018-03-01
   * @param haggleId
   */
  getHaggleDetail(params): Observable<SNSResult<HaggleActivityRespVO >> {
    const url = API.GET_HAGGLE_DETAIL + '?' + this.tools.param(params);
    return this.httpService.get(url).map((res: Response) => res.json());
  }

  // 发起砍价活动
  postHaggleInitiate(data): Observable<SNSResult<number>> {
    const url = API.POST_HAGGLE_INITIATE;
    return this.httpService.postUrlencodeStr(url, data)
      .map((res: Response) => res.json());
  }

  // 砍一刀减金额 @modify zhupw1360 - 20180403
  postHaggleSum(data): Observable<SNSResult<number>> {
    const url = API.POST_HAGGLE_SUM;
    return this.httpService.postUrlencodeStr(url, data)
      .map((res: Response) => res.json());
  }

  // 获取帮忙砍价用户列表
  getHaggleUsers(params): Observable<SNSResult<CommonPageVo<HaggleInitiatorRespVO>>> {
    const url = API.GET_HAGGLE_USERS + '?' + this.tools.param(params);
    return this.httpService.get(url).map((res) => res.json());
  }

  // 我的砍价
  getMyHaggleList(params): Observable<SNSResult<CommonPageVo<GoodsResp>>> {
    const url = API.GET_HAGGLE_MY_LIST + '?' + this.tools.param(params);
    return this.httpService.get(url).map((res) => res.json());
  }

}
